<template>
    <div class="modelBox">
        <div class="modelTitle">照片级写实效果 图片即广告</div>
        <div class="modelContent">细腻质感还原，细节一眼看得见</div>
        <div class="materType">
            <div class="materTypeTitle" v-for="(item, index) in materList" :key="index" :class="activeType == index ? 'activeTitle' : 'materTypeTitle'" @click="chooseType(item, index)">
                <div class="materTypeImg">
                    {{ item.name }}

                    <img :src="getImg(item.imgActive)" alt="" v-if="activeType == index" />
                    <img :src="getImg(item.imgUrl)" alt="" v-else />
                </div>
                <div class="triangle" v-if="activeType == index"></div>
            </div>
        </div>
        <div class="modelBtn">
            <div v-for="i in 4" :key="i">
                <div class="modelBtnBox" v-for="(item, index) in getFilteredList(btnList, i)" :key="index">
                    <div class="modelBtnImgHigh" v-if="(i % 2 !== 0 && index % 2 !== 0) || (i % 2 == 0 && index % 2 == 0)">
                        <div class="more">
                            <img src="@/assets/svg/tubusi_w_index_pic.svg" alt="" />
                            <div class="moreText">看更多(2)</div>
                        </div>
                    </div>
                    <div class="modelBtnImg" v-else>
                        <div class="more">
                            <img src="@/assets/svg/tubusi_w_index_pic.svg" alt="" />
                            <div class="moreText">看更多(2)</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
const activeType = ref(0);
const svgModules = import.meta.glob("~/assets/svg/active/*.svg", { eager: true });

const getImg = (cardContent) => {
    const key = `/assets/svg/active/${cardContent}.svg`;
    return svgModules[key]?.default || "/fallback.svg";
};
const materList = ref([
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
]);
const btnList = ref([
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
]);
// 定义一个普通函数来处理数据
const getFilteredList = (list, i) => {
    const startIndex = (i - 1) * 2;
    const endIndex = startIndex + 2;
    return list.slice(startIndex, endIndex);
};
const chooseType = (item, index) => {
    activeType.value = index;
};
</script>

<style lang="less" scoped>
.modelBox {
    background: var(white);
    padding-bottom: 140px;
    .materType {
        display: flex;
        justify-content: center;
        margin-top: 60px;
        margin-bottom: 46px;
        .materTypeTitle {
            height: 60px;
            background: var(--white);
            box-shadow: 0px 0px 20px 0px var(--shadow);
            border-radius: 8px;
            margin: 0 10px;
            padding: 0 20px;
            position: relative;
            cursor: pointer;
            .materTypeImg {
                height: 24px;
                margin-top: 18px;
                line-height: 24px;
                font-weight: 500;
                font-size: 16px;
                color: var(--black);
                line-height: 24px;
                display: flex;

                img {
                    width: 24px;
                    height: 24px;
                    margin-left: 20px;
                }
            }
            .triangle {
                width: 16px;
                height: 16px;
                background: var(--black);
                position: absolute;
                left: 50%;
                transform: translateX(-50%) translateY(50%) rotate(45deg);
            }
        }
        .activeTitle {
            height: 60px;
            background: var(--white);
            box-shadow: 0px 0px 20px 0px var(--shadow);
            border-radius: 8px;
            margin: 0 10px;
            padding: 0 20px;
            position: relative;
            background: var(--black);
            .materTypeImg {
                height: 24px;
                margin-top: 18px;
                line-height: 24px;
                font-weight: 500;
                font-size: 16px;
                color: var(--white);
                line-height: 24px;
                display: flex;

                img {
                    width: 24px;
                    height: 24px;
                    margin-left: 20px;
                }
            }
            .triangle {
                width: 16px;
                height: 16px;
                background: var(--black);
                position: absolute;
                left: 50%;
                transform: translateX(-50%) translateY(50%) rotate(45deg);
            }
        }
    }
    .modelBtn {
        display: flex;
        justify-content: center;
        .modelBtnBox {
            width: 315px;
            margin: 0 15px;
            .more {
                width: 120px;
                height: 32px;
                background: var(--shadowTab);
                border-radius: 8px;
                backdrop-filter: blur(10px);
                position: absolute;
                bottom: 20px;
                left: 30px;
                display: flex;
                align-items: center;
                img {
                    width: 20px;
                    height: 20px;
                    margin-left: 12px;
                    margin-right: 8px;
                }
                .moreText {
                    font-weight: 500;
                    font-size: 14px;
                    color: var(--white);
                    line-height: 20px;
                }
            }
            .modelBtnImg {
                position: relative;
                width: 315px;
                height: 240px;
                background: var(--shadow);
                border-radius: 24px;
                margin: 30px 0;
            }
            .modelBtnImgHigh {
                position: relative;
                width: 315px;
                height: 424px;
                background: var(--shadow);
                border-radius: 24px;
                margin: 30px 0;
            }
        }
    }
}
.modelTitle {
    font-weight: 600;
    font-size: 40px;
    color: var(black);
    line-height: 56px;
    width: 100%;
    padding-top: 140px;
    box-sizing: border-box;
    text-align: center;
}
.modelContent {
    width: 100%;
    font-weight: 400;
    font-size: 20px;
    color: var(black);
    line-height: 28px;
    text-align: center;
    margin-top: 16px;
}
</style>
